import { LoginDTO } from './../models/general';
<template>
  <div class="login-container">

    <!-- 登录表单模块 -->
    <div class="login-box">
      <h1>智能铁路售票系统</h1>
      <h2>用户登录</h2>
      <el-form :model="loginForm" :rules="rules" label-width="0" class="login-form">
        <el-form-item prop="account">
          <el-input v-model="loginForm.account" placeholder="账号">
            <template #prefix>
              <el-icon><User/></el-icon>
            </template>
          </el-input>
        </el-form-item>
        
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" type="password" placeholder="密码" show-password>
            <template #prefix>
              <el-icon><Lock/></el-icon>
            </template>
          </el-input>
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" @click="submitForm" class="login-btn">登录</el-button>
        </el-form-item>
        
        <el-form-item>
          <el-button @click="register" class="register-btn">注册</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script lang="ts">

import { User, Lock } from '@element-plus/icons-vue'
import { defineComponent } from 'vue';
import { type LoginDTO } from '../models/general'
import { loginMethod, registerRequest, generalRequest } from '../request/generalRequest';
import  router  from '../router/index.ts';



export default defineComponent({
        components: { // 显式注册图标组件
    User,
    Lock
  },
  
   data:() =>({
    loginForm: {} as LoginDTO,
    rules: {
      account: [
        { required: true, message: '请输入账号', trigger: 'blur' }],
      password: [
        { required: true, message: '请输入密码', trigger: 'blur' }]
    }
}),

   created() {
      
  },

  methods:{
    //登录逻辑
  async submitForm()
  {
      const result = await loginMethod('/api/user/login',this.loginForm); 
      console.log(result);
      
      if(result.code === 1)
      {
        alert("登录成功！")
        router.push(
           
          { path: '/HelloWorld' }
          );
      }
      else{
        alert("登录失败！请检查用户名和密码是否正确！");

      }
  },

  //跳转到注册页面
    register (){
        router.push(
          { path: '/Register' }
          );
 }
  },




})








</script>


<style scoped>
.login-container {
  background: url('public/login_and_register/background_login.jpg') no-repeat center center fixed;
  background-size: cover;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 50px;
}

.login-box {
  background-color: rgba(255, 255, 255, 0.8);
  padding: 30px;
  border-radius: 8px;
  width: 350px;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
}

.login-form :deep(.el-form-item__content) {
  width: 100%;
}

.login-btn, .register-btn {
  width: 100%;
}

.login-form :deep(.el-input__prefix) {
  display: flex;
  align-items: center;
}
</style>